/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 * MenuCadastrarFuncionario.java
 *
 * Created on 21/09/2009, 10:27:07
 */


package JPaneis;

import Conector.Conector;
import Data.Funcionario;
import Data.Pessoa;
import Data.ServicoPesca;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import siii.MenuPadrao;


public class MenuCadastrarFuncionario extends javax.swing.JPanel implements panelTools{

    private MenuPadrao menuPadrao;
    private Funcionario funcionario;
    private Conector conector;
    private String objetivo;
    private JDialog mensagem;
    private boolean flagCpf = false;
    private boolean flagCpfBD = true;
    private boolean flagFuncEncontrado = false;
    private ImageIcon iconeOK;
    private ImageIcon iconeERRO;
    private ImageIcon iconeATENCAO;

    /** Creates new form MenuCadastrarFuncionario */

    public MenuCadastrarFuncionario(MenuPadrao m, String e, Conector con) {
        this.menuPadrao = m;
        this.conector = con;
        this.objetivo = e;        //se for Atualizar
        initComponents();
        if(this.objetivo.equals("e"))
            jButtonExcluir.setVisible(false);

        else if(this.objetivo.equals("c")) {
            jButtonExcluir.setVisible(false);
            jButtonBuscar.setVisible(false);
        }
        else
        {
            jButtonSalvar.setVisible(false);
        }
        validaData.setVisible(false);
        validaCPF.setVisible(false);
        validaSenha.setVisible(false);
        iconeOK = new ImageIcon(getClass().getResource("/Images/fish-48x48ok.png"));
        iconeERRO = new ImageIcon(getClass().getResource("/Images/fish-48x48erro.png"));
        iconeATENCAO = new ImageIcon(getClass().getResource("/Images/fish-48x48atencao1.png"));
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        funcCel = new javax.swing.JFormattedTextField();
        funcCep = new javax.swing.JFormattedTextField();
        funcTel = new javax.swing.JFormattedTextField();
        funcName = new javax.swing.JFormattedTextField();
        funcCpf = new javax.swing.JFormattedTextField();
        jLabelName = new javax.swing.JLabel();
        jLabelNick = new javax.swing.JLabel();
        jLabelSex = new javax.swing.JLabel();
        jLabelLastName = new javax.swing.JLabel();
        jButtonSalvar = new javax.swing.JButton();
        jLabelTel = new javax.swing.JLabel();
        jLabelCel = new javax.swing.JLabel();
        jLabelCadastroFuncionario = new javax.swing.JLabel();
        jLabelCep = new javax.swing.JLabel();
        jLabelCPF = new javax.swing.JLabel();
        jLabelRG = new javax.swing.JLabel();
        funcAddr = new javax.swing.JFormattedTextField();
        jLabelAddr = new javax.swing.JLabel();
        funcNasc = new javax.swing.JFormattedTextField();
        funcNeigh = new javax.swing.JFormattedTextField();
        jLabelNeigh = new javax.swing.JLabel();
        funcLastName = new javax.swing.JFormattedTextField();
        jButtonCancelar = new javax.swing.JButton();
        funcPasswd = new javax.swing.JPasswordField();
        jLabelPasswd = new javax.swing.JLabel();
        jLabelNasc = new javax.swing.JLabel();
        jLabelRePasswd = new javax.swing.JLabel();
        funcRePasswd = new javax.swing.JPasswordField();
        funcNick = new javax.swing.JFormattedTextField();
        jLabelCity = new javax.swing.JLabel();
        jLabelState = new javax.swing.JLabel();
        jLabelAddNum = new javax.swing.JLabel();
        funcAddNum = new javax.swing.JTextField();
        funcCity = new javax.swing.JTextField();
        jButtonBuscar = new javax.swing.JButton();
        funcSexo = new javax.swing.JComboBox();
        funcState = new javax.swing.JComboBox();
        validaCPF = new javax.swing.JLabel();
        validaData = new javax.swing.JLabel();
        validaSenha = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        funcRg = new javax.swing.JFormattedTextField();
        jButtonExcluir = new javax.swing.JButton();
        validaSenha1 = new javax.swing.JLabel();
        validaSenha2 = new javax.swing.JLabel();
        validaSenha3 = new javax.swing.JLabel();
        validaSenha4 = new javax.swing.JLabel();
        validaSenha5 = new javax.swing.JLabel();
        validaSenha6 = new javax.swing.JLabel();
        validaSenha7 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(1000, 500));

        try {
            funcCel.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        funcCel.setFocusLostBehavior(javax.swing.JFormattedTextField.PERSIST);
        funcCel.setName("Celular"); // NOI18N

        try {
            funcCep.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("#####-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        funcCep.setFocusLostBehavior(javax.swing.JFormattedTextField.PERSIST);
        funcCep.setName("CEP"); // NOI18N

        try {
            funcTel.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        funcTel.setFocusLostBehavior(javax.swing.JFormattedTextField.PERSIST);
        funcTel.setName("Telefone"); // NOI18N

        funcName.setName("Nome"); // NOI18N

        try {
            funcCpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        funcCpf.setFocusLostBehavior(javax.swing.JFormattedTextField.PERSIST);
        funcCpf.setName("CPF"); // NOI18N
        funcCpf.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                funcCpfFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                funcCpfFocusLost(evt);
            }
        });

        jLabelName.setText("Nome");

        jLabelNick.setText("Apelido");

        jLabelSex.setText("Sexo");

        jLabelLastName.setText("Sobrenome");

        jButtonSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/peixe_add.png"))); // NOI18N
        jButtonSalvar.setText("Salvar");
        jButtonSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSalvarActionPerformed(evt);
            }
        });

        jLabelTel.setText("Telefone");

        jLabelCel.setText("Celular");

        jLabelCadastroFuncionario.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabelCadastroFuncionario.setText("Cadastro de Funcionário");

        jLabelCep.setText("CEP");

        jLabelCPF.setText("C.P.F");

        jLabelRG.setText("R.G");

        funcAddr.setName("Logradouro"); // NOI18N

        jLabelAddr.setText("Endereço");

        try {
            funcNasc.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        funcNasc.setFocusLostBehavior(javax.swing.JFormattedTextField.PERSIST);
        funcNasc.setName("Data_Nascimento"); // NOI18N
        funcNasc.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                funcNascFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                funcNascFocusLost(evt);
            }
        });

        funcNeigh.setName("Bairro"); // NOI18N

        jLabelNeigh.setText("Bairro");

        funcLastName.setName("Sobrenome"); // NOI18N

        jButtonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/peixe_cancelar.png"))); // NOI18N
        jButtonCancelar.setText("Cancelar");
        jButtonCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mouseClickedCancelar(evt);
            }
        });

        funcPasswd.setName("Senha"); // NOI18N

        jLabelPasswd.setText("Senha");

        jLabelNasc.setText("Data Nascimento");

        jLabelRePasswd.setText("Repita Senha");

        funcRePasswd.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                funcRePasswdFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                funcRePasswdFocusLost(evt);
            }
        });

        funcNick.setName("Apelido"); // NOI18N

        jLabelCity.setText("Cidade");

        jLabelState.setText("Estado");

        jLabelAddNum.setText("Número");

        funcAddNum.setName("Numero"); // NOI18N

        funcCity.setName("Cidade"); // NOI18N

        jButtonBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/fish-48x48buscar.png"))); // NOI18N
        jButtonBuscar.setText("Buscar");
        jButtonBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarFuncionario(evt);
            }
        });

        funcSexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Masculino", "Feminino" }));
        funcSexo.setName("Sexo"); // NOI18N

        funcState.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SP", "AC", "AL", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MG", "MS", "PA", "PB", "PE", "PI", "PR", "RJ", "RR", "RO", "RS", "RN", "SP", "SC", "SE", "TO" }));

        validaCPF.setForeground(new java.awt.Color(255, 0, 0));
        validaCPF.setText("CPF Inválido");

        validaData.setForeground(new java.awt.Color(255, 0, 0));
        validaData.setText("Data Inválida");

        validaSenha.setForeground(new java.awt.Color(255, 0, 0));
        validaSenha.setText("Confirmação Inválida");

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/peixe_limpar.png"))); // NOI18N
        jButton1.setText("Limpar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1jButtonLimpar(evt);
            }
        });

        try {
            funcRg.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###-*")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        funcRg.setFocusLostBehavior(javax.swing.JFormattedTextField.PERSIST);

        jButtonExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/peixe_cancelar2.png"))); // NOI18N
        jButtonExcluir.setText("Excluir");
        jButtonExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonExcluirjButtonLimpar(evt);
            }
        });

        validaSenha1.setForeground(new java.awt.Color(255, 0, 0));
        validaSenha1.setText("*");

        validaSenha2.setForeground(new java.awt.Color(255, 0, 0));
        validaSenha2.setText("*");

        validaSenha3.setForeground(new java.awt.Color(255, 0, 0));
        validaSenha3.setText("*");

        validaSenha4.setForeground(new java.awt.Color(255, 0, 0));
        validaSenha4.setText("*");

        validaSenha5.setForeground(new java.awt.Color(255, 0, 0));
        validaSenha5.setText("*");

        validaSenha6.setForeground(new java.awt.Color(255, 0, 0));
        validaSenha6.setText("*");

        validaSenha7.setForeground(new java.awt.Color(255, 0, 0));
        validaSenha7.setText("*");

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/funcionario.png"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCancelar))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(validaSenha1, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(validaSenha2, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(validaSenha4, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(validaSenha6, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(224, 224, 224)
                                                .addComponent(jLabelCadastroFuncionario, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)
                                                .addGap(17, 17, 17))
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addGap(500, 500, 500)
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                            .addComponent(jLabelAddNum)
                                                            .addComponent(jLabelCep, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                            .addComponent(funcCep, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                            .addComponent(funcAddNum, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)))
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                            .addComponent(jLabelSex)
                                                            .addComponent(jLabelAddr, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                                .addComponent(jLabelNeigh, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                                .addComponent(jLabelCity, javax.swing.GroupLayout.Alignment.LEADING))
                                                            .addComponent(jLabelTel))
                                                        .addGap(45, 45, 45)
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                                .addComponent(funcCity, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addGap(38, 38, 38)
                                                                .addComponent(jLabelState)
                                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                                .addComponent(funcState, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                            .addComponent(funcNeigh, javax.swing.GroupLayout.Alignment.LEADING)
                                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                                    .addComponent(funcAddr, javax.swing.GroupLayout.Alignment.LEADING)
                                                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                                        .addComponent(funcSexo, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addGap(19, 19, 19)
                                                                        .addComponent(validaSenha7, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                        .addComponent(jLabelNasc)
                                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                        .addComponent(funcNasc, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE))))
                                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                                .addComponent(funcTel, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addGap(18, 18, 18)
                                                                .addComponent(jLabelCel)
                                                                .addGap(26, 26, 26)
                                                                .addComponent(funcCel)))
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                        .addComponent(validaData, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                            .addGroup(layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabelRePasswd)
                                                    .addComponent(jLabelPasswd))
                                                .addGap(41, 41, 41)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addComponent(funcRePasswd, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(validaSenha))
                                                    .addComponent(funcPasswd, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(256, 256, 256)))
                                        .addGap(115, 115, 115)
                                        .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabelName, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabelNick)
                                            .addComponent(jLabelLastName))
                                        .addGap(55, 55, 55)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(funcNick, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(funcName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 361, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(funcLastName, javax.swing.GroupLayout.Alignment.LEADING))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(validaSenha3, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(4, 4, 4)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabelCPF)
                                            .addComponent(jLabelRG))
                                        .addGap(14, 14, 14)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(funcRg)
                                            .addComponent(funcCpf, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(validaCPF)
                                        .addGap(103, 103, 103))))
                            .addComponent(validaSenha5, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButtonExcluir, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonBuscar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGap(51, 51, 51))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelCadastroFuncionario)
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addComponent(jButtonExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(funcName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelName, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(validaSenha1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(funcLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelLastName, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(validaSenha2))
                                .addGap(10, 10, 10)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(funcNick, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelNick, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(validaSenha4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(validaSenha5)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabelPasswd)
                                        .addComponent(funcPasswd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabelCPF)
                                    .addComponent(funcCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(validaSenha3)
                                    .addComponent(validaCPF))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabelRG, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(funcRg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addGap(23, 23, 23))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(funcRePasswd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(validaSenha6)
                                    .addComponent(jLabelRePasswd)
                                    .addComponent(validaSenha))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(funcSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabelSex))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(funcNasc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabelNasc, javax.swing.GroupLayout.DEFAULT_SIZE, 16, Short.MAX_VALUE)
                                        .addComponent(validaSenha7)
                                        .addComponent(validaData)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(funcAddr, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelAddr, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelAddNum)
                                    .addComponent(funcAddNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(funcNeigh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelNeigh, javax.swing.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE))
                                .addGap(12, 12, 12)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabelCity)
                                    .addComponent(funcCity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelState)
                                    .addComponent(funcState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelCep, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                                    .addComponent(funcCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(funcTel, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelCel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(funcCel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelTel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                    .addComponent(jButtonBuscar))
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonSalvar)
                    .addComponent(jButtonCancelar))
                .addGap(69, 69, 69))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void mouseClickedCancelar(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mouseClickedCancelar
        // TODO add your handling code here:
        //MenuPadrao.trocaPanel("MenuCadastrarFuncionario", "MenuPrincipal");
        this.cleanScreen();
        menuPadrao.trocaPanel2(menuPadrao.getMenuPrincipal());
    }//GEN-LAST:event_mouseClickedCancelar

  public boolean valida_CpfCnpj(String s_aux)
    {
//------- Rotina para CPF
       if (s_aux.length() == 11 )
       {
           if (s_aux.equals("00000000000") || s_aux.equals("11111111111") || s_aux.equals("22222222222") || s_aux.equals("33333333333") || s_aux.equals("44444444444") || s_aux.equals("55555555555") || s_aux.equals("66666666666") || s_aux.equals("77777777777") || s_aux.equals("88888888888") || s_aux.equals("99999999999"))
                return false;  //colocar false depois, estes nao sao validos

           int     d1, d2;
           int     digito1, digito2, resto;
           int     digitoCPF;
           String  nDigResult;
           d1 = d2 = 0;
           digito1 = digito2 = resto = 0;
           for (int n_Count = 1; n_Count < s_aux.length() -1; n_Count++)
           {
              digitoCPF = Integer.valueOf (s_aux.substring(n_Count -1, n_Count)).intValue();
//--------- Multiplique a ultima casa por 2 a seguinte por 3 a seguinte por 4 e assim por diante.
              d1 = d1 + ( 11 - n_Count ) * digitoCPF;
//--------- Para o segundo digito repita o procedimento incluindo o primeiro digito calculado no passo anterior.
              d2 = d2 + ( 12 - n_Count ) * digitoCPF;
           }
//--------- Primeiro resto da divisão por 11.
           resto = (d1 % 11);
//--------- Se o resultado for 0 ou 1 o digito é 0 caso contrário o digito é 11 menos o resultado anterior.
           if (resto < 2)
              digito1 = 0;
           else
              digito1 = 11 - resto;
           d2 += 2 * digito1;
//--------- Segundo resto da divisão por 11.
           resto = (d2 % 11);
//--------- Se o resultado for 0 ou 1 o digito é 0 caso contrário o digito é 11 menos o resultado anterior.
           if (resto < 2)
              digito2 = 0;
           else
              digito2 = 11 - resto;
//--------- Digito verificador do CPF que está sendo validado.
           String nDigVerific = s_aux.substring (s_aux.length()-2, s_aux.length());
//--------- Concatenando o primeiro resto com o segundo.
           nDigResult = String.valueOf(digito1) + String.valueOf(digito2);
//--------- Comparar o digito verificador do cpf com o primeiro resto + o segundo resto.
           return nDigVerific.equals(nDigResult);
        }
//-------- Rotina para CNPJ
        else if (s_aux.length() == 14)
        {
            int soma = 0, aux, dig;
            String cnpj_calc = s_aux.substring(0,12);
            char[] chr_cnpj = s_aux.toCharArray();
//--------- Primeira parte
            for( int i = 0; i < 4; i++ )
            if ( chr_cnpj[i]-48 >=0 && chr_cnpj[i]-48 <=9 )
              soma += (chr_cnpj[i] - 48) * (6 - (i + 1));
            for( int i = 0; i < 8; i++ )
            if ( chr_cnpj[i+4]-48 >=0 && chr_cnpj[i+4]-48 <=9 )
                soma += (chr_cnpj[i+4] - 48) * (10 - (i + 1));
            dig = 11 - (soma % 11);
            cnpj_calc += ( dig == 10 || dig == 11 ) ?
                "0" : Integer.toString(dig);
//--------- Segunda parte
            soma = 0;
            for ( int i = 0; i < 5; i++ )
            if ( chr_cnpj[i]-48 >=0 && chr_cnpj[i]-48 <=9 )
                soma += (chr_cnpj[i] - 48) * (7 - (i + 1));
            for ( int i = 0; i < 8; i++ )
            if ( chr_cnpj[i+5]-48 >=0 && chr_cnpj[i+5]-48 <=9 )
                soma += (chr_cnpj[i+5] - 48) * (10 - (i + 1));
            dig = 11 - (soma % 11);
            cnpj_calc += ( dig == 10 || dig == 11 ) ?
                        "0" : Integer.toString(dig);
            return s_aux.equals(cnpj_calc);
        }
        else
            return false;
    }

 /**
 * Guarda dados do funcionario
 */
private void jButtonSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSalvarActionPerformed

     if(funcName.getText().length() > 0) {
         if(funcLastName.getText().compareTo("") != 0) {
             if(funcNick.getText().length() > 0) {
                    if((!funcNasc.getText().equals("  /  /    "))) {
                        if(this.validaData()) {
                try {
                    if (this.objetivo.equals("c")) {
                       if(this.validacaoSenha()) {
                        if(flagCpf && !flagCpfBD) {
                        try {
                            funcionario = readScreen();
                            if (conector.cadastrarFuncionario(funcionario)) {
                                JOptionPane.showMessageDialog(this, "O funcionario " + funcionario.getNome() + " foi cadastrado", "Confirmação", JOptionPane.INFORMATION_MESSAGE, iconeOK);
                                funcionario = null;
                                flagCpf = false;
                                flagCpfBD = true;
                                cleanScreen();
                                menuPadrao.trocaPanel2(menuPadrao.getMenuPrincipal());
                            } else {
                                JOptionPane.showMessageDialog(this, "O funcionario NÃO foi cadastrado", "Atenção", JOptionPane.WARNING_MESSAGE, iconeERRO);
                                //menuPadrao.trocaPanel2(menuPadrao.getMenuPrincipal());
                            }

                        } catch (SQLException sqle) {

                            Logger.getLogger(MenuCadastrarFuncionario.class.getName()).log(Level.SEVERE, null, sqle);
                            conector = new Conector();
                        }
                 
                        }
                        else {
                            if(!flagCpf)
                                JOptionPane.showMessageDialog(this, "Favor informar CPF válido", "Atenção", JOptionPane.WARNING_MESSAGE, iconeATENCAO);
                            else if(flagCpfBD)
                                JOptionPane.showMessageDialog(this, "CPF já cadastrado", "Atenção", JOptionPane.WARNING_MESSAGE, iconeATENCAO);
                        }
                        } else
                                JOptionPane.showMessageDialog(this, "Senha inválida", "AVISO", JOptionPane.WARNING_MESSAGE, iconeATENCAO);
                    } else {

                        try {
                            funcionario = readScreen();                            
                            if (conector.atualizarCadastroFuncionario(readScreen())) {
                                JOptionPane.showMessageDialog(this, "O cadastro do funcionario " + funcionario.getNome() + " foi atualizado", "Atualização", JOptionPane.WARNING_MESSAGE, iconeOK);
                                cleanScreen();
                                menuPadrao.trocaPanel2(menuPadrao.getMenuPrincipal());

                            } else {
                                JOptionPane.showMessageDialog(this, "O funcionario NÃO pôde ser atualizado", "Atenção", JOptionPane.WARNING_MESSAGE, iconeERRO);
                                menuPadrao.trocaPanel2(menuPadrao.getMenuPrincipal());
                            }


                        } catch (SQLException sqle) {

                            Logger.getLogger(MenuCadastrarFuncionario.class.getName()).log(Level.SEVERE, null, sqle);
                            conector = new Conector();
                        }
                    }

                } catch (Exception ex) {

                    ex.printStackTrace();
                    conector = new Conector();
                }

                 } else
                 JOptionPane.showMessageDialog(this, "Data de nascimento inválida", "AVISO", JOptionPane.WARNING_MESSAGE, iconeERRO);
                 } else
                 JOptionPane.showMessageDialog(this, "Favor preencher campo Data de nascimento", "AVISO", JOptionPane.WARNING_MESSAGE, iconeATENCAO);
        } else
            JOptionPane.showMessageDialog(this, "Favor preencher campo Apelido", "AVISO", JOptionPane.WARNING_MESSAGE, iconeATENCAO);
     } else
         JOptionPane.showMessageDialog(this, "Favor preencher campo Sobrenome", "AVISO", JOptionPane.WARNING_MESSAGE, iconeATENCAO);
     } else
         JOptionPane.showMessageDialog(this, "Favor preencher campo Nome", "AVISO", JOptionPane.WARNING_MESSAGE, iconeATENCAO);

     funcCpf.setEditable(true);
}//GEN-LAST:event_jButtonSalvarActionPerformed

private void jButtonBuscarFuncionario(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarFuncionario
    // TODO add your handling code here:

    String cpf = funcCpf.getText().replace(".", "").replace("-", "").replace(" ", "");

    funcionario = new Funcionario(funcName.getText(), funcLastName.getText(), cpf, funcNick.getText());

    try {
        Funcionario func = conector.consultarFuncionarioParaEditar(funcionario, this);
            if(func.isFlagFuncionarioNaoCadastrado())
                JOptionPane.showMessageDialog(this, "Funcionário não encontrado", "Atenção", JOptionPane.WARNING_MESSAGE, iconeERRO);         
            else {
                setFuncScreen(func);
                flagFuncEncontrado = true;
            }

        } catch (SQLException ex) {
            Logger.getLogger(MenuCadastrarFuncionario.class.getName()).log(Level.SEVERE, null, ex);
            conector = new Conector();
        }

    funcCpf.setEditable(false);

}//GEN-LAST:event_jButtonBuscarFuncionario

private void funcRePasswdFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_funcRePasswdFocusLost
      if(funcPasswd.getText().compareTo(funcRePasswd.getText()) == 0)
      {
        validaSenha.setVisible(false);   // TODO add your handling code here:
      }
      else
          validaSenha.setVisible(true);
}//GEN-LAST:event_funcRePasswdFocusLost

private void funcRePasswdFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_funcRePasswdFocusGained
    validaSenha.setVisible(false);// TODO add your handling code here:

}//GEN-LAST:event_funcRePasswdFocusGained

private void funcCpfFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_funcCpfFocusLost

    this.validaCpf();
}//GEN-LAST:event_funcCpfFocusLost

private void validaCpf() {
    
    flagCpf = false;
    flagCpfBD = true;

    if(valida_CpfCnpj(funcCpf.getText().replace(" ", "").replace(".","").replace("-",""))) {   // TODO add your handling code here:
       flagCpf = true;
    }
    else {
        validaCPF.setVisible(true);
        flagCpf = false;
    }

   if(flagCpf) {
       
            try {
                if(conector.consultaCPFCadastrado(funcCpf.getText().replace(" ", "").replace(".", "").replace("-", ""), "funcionarios"))
                    flagCpfBD = true;
                else
                    flagCpfBD = false;

            } catch (SQLException ex) {
                Logger.getLogger(MenuCadastrarFuncionario.class.getName()).log(Level.SEVERE, null, ex);
                conector = new Conector();
            }
   }
}

private void funcCpfFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_funcCpfFocusGained
    validaCPF.setVisible(false);
    flagCpf = false;
}//GEN-LAST:event_funcCpfFocusGained

private void funcNascFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_funcNascFocusGained
    validaData.setVisible(false);// TODO add your handling code here:
}//GEN-LAST:event_funcNascFocusGained

private void funcNascFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_funcNascFocusLost
    validaData();
}//GEN-LAST:event_funcNascFocusLost

private void jButton1jButtonLimpar(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1jButtonLimpar
    cleanScreen();
    validaCPF.setVisible(false);
    validaData.setVisible(false);
    validaSenha.setVisible(false);
}//GEN-LAST:event_jButton1jButtonLimpar

private void jButtonExcluirjButtonLimpar(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonExcluirjButtonLimpar
    // TODO add your handling code here:
    String cpf;
    try {
    if(flagFuncEncontrado) {
        cpf = funcCpf.getText().substring(0, 3) + funcCpf.getText().substring(4, 7) + funcCpf.getText().substring(8, 11) + funcCpf.getText().substring(12, 14);
        if(conector.excluirCadastroFuncionario(cpf))
            JOptionPane.showMessageDialog(this, "Funcionario excluido com sucesso", "Confirmação", JOptionPane.WARNING_MESSAGE, iconeOK);
            cleanScreen();
            flagFuncEncontrado = false;
    }
    else
        JOptionPane.showMessageDialog(this, "Favor buscar funcionário antes", "Atenção", JOptionPane.WARNING_MESSAGE, iconeATENCAO);
    }
    catch(Exception e) {
        e.printStackTrace();
        conector = new Conector();
    }
}//GEN-LAST:event_jButtonExcluirjButtonLimpar

public boolean validaData() {
        String[] data = funcNasc.getText().split("/");
            int dia;  int mes; int ano;
        try {
            dia = Integer.parseInt(data[0]);
            mes = Integer.parseInt(data[1]);
            ano = Integer.parseInt(data[2]);
        } catch (NumberFormatException e) {
            return false;
        }


        try {
            Date dateTest = Funcionario.dateCreator.parse(funcNasc.getText());
            long funcTime = dateTest.getTime();
            long sysTime = System.currentTimeMillis();
            if (sysTime < funcTime) {
                    validaData.setVisible(true);
                    return false;
            }
        } catch (ParseException ex) {
            Logger.getLogger(MenuCadastrarFuncionario.class.getName()).log(Level.SEVERE, null, ex);
            conector = new Conector();
        }



        if (mes > 0 && mes <= 12) {

            if (ano % 4 == 0) { //VERIFICA ANO BISSEXTO
                if (mes == 2) {
                    if (dia < 0 || dia > 29) {
                        validaData.setVisible(true);
                        return false;
                    } else {
                        return true;
                    }
                } else {
                    if (dia < 0 || dia > 28) {
                        validaData.setVisible(true);
                        return false;
                    } else {
                        validaData.setVisible(false);
                        return true;
                    }
                }
            } else {
                if (mes == 2) {

                    if (dia < 0 || dia > 28) {
                        validaData.setVisible(true);
                        return false;
                    } else {
                        validaData.setVisible(false);
                        return true;
                    }
                } else if (ano % 2 == 0) {
                    if (dia < 0 || dia > 30) {
                        validaData.setVisible(true);
                        return false;
                    } else {
                        validaData.setVisible(false);
                        return true;
                    }
                } else if (dia < 0 || dia > 31) {
                    validaData.setVisible(true);
                    return false;
                } else {
                    validaData.setVisible(false);
                    return true;
                }

            }
        } else {
            validaData.setVisible(true);
            return false;
        }
    }

    private Funcionario readScreen() throws ParseException {

        String cpf, telefone, celular, cep, sexo, estado, rg;

        if(funcCpf.getText().compareTo("   .   .   -  ") != 0)
            cpf = funcCpf.getText().substring(0, 3) + funcCpf.getText().substring(4, 7) + funcCpf.getText().substring(8, 11) + funcCpf.getText().substring(12, 14);
        else
            cpf = "";

        if(funcTel.getText().compareTo("(  )    -    ") != 0)
            telefone = funcTel.getText().substring(1, 3) + funcTel.getText().substring(4, 8) + funcTel.getText().substring(9, 13);
        else
            telefone = "";

        if(funcCel.getText().compareTo("(  )    -    ") != 0)
            celular = funcCel.getText().substring(1, 3) + funcCel.getText().substring(4, 8) + funcCel.getText().substring(9, 13);
        else
            celular = "";

        if(funcCep.getText().compareTo("     -   ") != 0)
            cep = funcCep.getText().substring(0, 5) + funcCep.getText().substring(6, 9);
        else
            cep = "";

        if(funcRg.getText().compareTo("  .   .   - ") != 0)
            rg = funcRg.getText().substring(0, 2) + funcRg.getText().substring(3, 6) + funcRg.getText().substring(7, 10) + funcRg.getText().substring(11);
        else
            rg = "";

            sexo = funcSexo.getSelectedItem().toString();
            estado = funcState.getSelectedItem().toString();
 

       Funcionario func = new Funcionario(cpf, funcName.getText(), funcLastName.getText(), funcAddr.getText(),
                funcAddNum.getText(), funcNeigh.getText(), funcCity.getText(), estado,
                cep, telefone, celular, funcPasswd.getText(), funcNick.getText(), funcNasc.getText(),
                sexo, rg);
       System.out.println(func.getRg());
       return func;
    }


    private boolean validacaoSenha() {
        if((this.funcPasswd.getText().length() == 0) || (this.funcRePasswd.getText().length() == 0) || this.funcPasswd.getText().compareTo(this.funcRePasswd.getText()) != 0)
            return false;
        else
            return true;
    }
    private void setFuncScreen() {
        setFuncScreen(funcionario);
    }

    public void setFuncScreen(Funcionario setFunc) {


        funcName.setText(setFunc.getNome());
        funcLastName.setText(setFunc.getSobrenome());
        funcNick.setText(setFunc.getApelido());
        funcAddr.setText(setFunc.getLogradouro());
        funcAddNum.setText(setFunc.getNumero());
        funcCity.setText(setFunc.getCidade());
        funcCpf.setText(setFunc.getCpf());
        funcCep.setText(setFunc.getCep());
        funcCel.setText(setFunc.getCelular());
        funcNasc.setText(setFunc.getDataNascimento());
        funcNeigh.setText(setFunc.getBairro());
        funcPasswd.setText(setFunc.getSenha());
        funcRg.setText(setFunc.getRg());
        funcSexo.setSelectedItem(setFunc.getSexo());
        funcState.setSelectedItem(setFunc.getEstado());
        funcTel.setText(setFunc.getTelefone());

        if(setFunc.getSexo() == null)
            funcSexo.setSelectedItem("Masculino");
        else if (setFunc.getSexo().equals("M")) {
            funcSexo.setSelectedItem("Masculino");
        } else {
            funcSexo.setSelectedItem("Feminino");
        }
}

    private void cleanScreen() {
        funcName.setText("");
        funcLastName.setText("");
        funcNick.setText("");
        funcAddr.setText("");
        funcAddNum.setText("");
        funcCep.setText("");
        funcCity.setText("");
        funcCpf.setText("");
        funcCel.setText("");
        funcNasc.setText("");
        funcNeigh.setText("");
        funcRg.setText("");
        funcState.setSelectedIndex(0);
        funcTel.setText("");
        funcSexo.setSelectedIndex(0);
        funcPasswd.setText("");
        funcRePasswd.setText("");
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField funcAddNum;
    private javax.swing.JFormattedTextField funcAddr;
    private javax.swing.JFormattedTextField funcCel;
    private javax.swing.JFormattedTextField funcCep;
    private javax.swing.JTextField funcCity;
    private javax.swing.JFormattedTextField funcCpf;
    private javax.swing.JFormattedTextField funcLastName;
    private javax.swing.JFormattedTextField funcName;
    private javax.swing.JFormattedTextField funcNasc;
    private javax.swing.JFormattedTextField funcNeigh;
    private javax.swing.JFormattedTextField funcNick;
    private javax.swing.JPasswordField funcPasswd;
    private javax.swing.JPasswordField funcRePasswd;
    private javax.swing.JFormattedTextField funcRg;
    private javax.swing.JComboBox funcSexo;
    private javax.swing.JComboBox funcState;
    private javax.swing.JFormattedTextField funcTel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonBuscar;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonExcluir;
    private javax.swing.JButton jButtonSalvar;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabelAddNum;
    private javax.swing.JLabel jLabelAddr;
    private javax.swing.JLabel jLabelCPF;
    private javax.swing.JLabel jLabelCadastroFuncionario;
    private javax.swing.JLabel jLabelCel;
    private javax.swing.JLabel jLabelCep;
    private javax.swing.JLabel jLabelCity;
    private javax.swing.JLabel jLabelLastName;
    private javax.swing.JLabel jLabelName;
    private javax.swing.JLabel jLabelNasc;
    private javax.swing.JLabel jLabelNeigh;
    private javax.swing.JLabel jLabelNick;
    private javax.swing.JLabel jLabelPasswd;
    private javax.swing.JLabel jLabelRG;
    private javax.swing.JLabel jLabelRePasswd;
    private javax.swing.JLabel jLabelSex;
    private javax.swing.JLabel jLabelState;
    private javax.swing.JLabel jLabelTel;
    private javax.swing.JLabel validaCPF;
    private javax.swing.JLabel validaData;
    private javax.swing.JLabel validaSenha;
    private javax.swing.JLabel validaSenha1;
    private javax.swing.JLabel validaSenha2;
    private javax.swing.JLabel validaSenha3;
    private javax.swing.JLabel validaSenha4;
    private javax.swing.JLabel validaSenha5;
    private javax.swing.JLabel validaSenha6;
    private javax.swing.JLabel validaSenha7;
    // End of variables declaration//GEN-END:variables

    public MenuPadrao getMenuPadrao() {
        return menuPadrao;
    }

    public void setScreen(Pessoa pessoa) {
        setFuncScreen((Funcionario) pessoa);
    }

    public void setScreen2(ServicoPesca servPesca) {
        throw new UnsupportedOperationException("Not supported yet.");
    }


}

